package com.right.health.app.net;

import com.magics.http.model.HttpParams;
import com.right.health.app.app.App;
import com.right.health.app.bean.AddressListResponse;
import com.right.health.app.bean.AppUserResponse;
import com.right.health.app.bean.PayInfo;
import com.right.health.app.bean.ServicePackResponse;
import com.right.health.app.bean.SocialNumberResponse;
import com.right.health.app.bean.SocialSecuritySign;
import com.right.health.app.bean.VisitCardResponse;

import org.json.JSONException;
import org.json.JSONObject;

/*
 * Created by hopeliao on 2019-11-01
 *
 */
public class UserApi extends IBaseApi {

    public void getVerificationCode(String phone) {
        HttpParams params = new HttpParams();
        params.addFormParam("mobile", phone);

        doPostJson(HttpConstants.API_GET_CODE, params, null);
    }

    public void delAccount(String phone) {
        HttpParams params = new HttpParams();
        params.addFormParam("mobile", phone);

        doPostJson(HttpConstants.API_DEL_USER, params, null);
    }

    public void verifyRegisterCode(String mobile, String code) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("mobile", mobile);
            jsonObject.put("code", code);
            jsonObject.put("openid", "");

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_VERIFY_REGISTER_CODE, params, AppUserResponse.class);
    }

    public void registerPwd(String mobile, String pwd) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("mobile", mobile);
            jsonObject.put("password", pwd);
            jsonObject.put("openid", "");

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_FINISH_REGISTER, params, AppUserResponse.class);
    }

    public void getFindPwdCode(String phone) {
        HttpParams params = new HttpParams();
        params.addFormParam("mobile", phone);
        doPostJson(HttpConstants.API_FIND_PWD_CODE, params, null);
    }

    public void verifyFindPwdCode(String mobile, String code) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("mobile", mobile);
            jsonObject.put("code", code);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_VERIFY_FIND_PWD_CODE, params, null);
    }

    public void resetPwd(String mobile, String pwd) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("mobile", mobile);
            jsonObject.put("password", pwd);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_FINISH_FIND_PWD, params, null);
    }


    public void login(String phone, String pwd) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("loginNo", phone);
            jsonObject.put("loginPwd", pwd);
            jsonObject.put("vipremark", "");
            jsonObject.put("openid", "");
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_LOGIN, params, AppUserResponse.class);
    }

    public void feedback(int type, String content, String phone) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("phone", phone);
            jsonObject.put("feedbacktype", type);
            jsonObject.put("feedbackdesc", content);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_ADD_FEEDBACK, params, null);
    }

    public void addVisitCard(String hospitalCode, String memberid) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("syscommunitycode", hospitalCode);
            jsonObject.put("memberid", memberid);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_ADD_VISITCARD, params, null);
    }

    public void getVisitCard(String memberid, int pageNo) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("memberid", memberid);
            PageUtil.addPageJson(jsonObject, pageNo, 50);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_VISITCARD_LIST, params, VisitCardResponse.class);
    }

    public void getUserInfo() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_USERINFO, params, AppUserResponse.class);
    }

    public void updateUserInfo(String avatarUrl) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("imageurl", avatarUrl);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_UPDATE_USERINFO, params, null);
    }

    public void getSocialSecurity() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_SOCIAL_SECURITY, params, SocialNumberResponse.class);
    }

    public void addSocialSecurity(String realname, String idcard, String phone) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("realname", realname);
            jsonObject.put("idcard", idcard);
            jsonObject.put("phone", phone);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_ADD_SOCIAL_SECURITY, params, null);
    }

    public void getSignCode() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_SIGN_CODE, params, SocialSecuritySign.class);
    }

    public void getAllArea() {
        HttpParams params = new HttpParams();
        params.addFormParam("jsonstr", "{}");
        doPostJson(HttpConstants.API_GET_ALL_AREA, params, null);
    }

    public void addShippingAddress(String name, String phone, int provinceId, int cityId, int areaId, String address) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("memberid", App.getInstance().getUser().memberid);
            jsonObject.put("username", name);
            jsonObject.put("userphone", phone);
            jsonObject.put("useraddress", address);
            jsonObject.put("provinceid", provinceId);
            jsonObject.put("cityid", cityId);
            jsonObject.put("countyid", areaId);
            jsonObject.put("isdefault", 0);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_ADD_SHIPPING_ADDRESS, params, null);
    }

    public void modifyShippingAddress(String id,String name, String phone, int provinceId, int cityId, int areaId, String address,String isDefault) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("addressid",id);
            jsonObject.put("memberid", App.getInstance().getUser().memberid);
            jsonObject.put("username", name);
            jsonObject.put("userphone", phone);
            jsonObject.put("useraddress", address);
            jsonObject.put("provinceid", provinceId);
            jsonObject.put("cityid", cityId);
            jsonObject.put("countyid", areaId);
            jsonObject.put("isdefault", isDefault);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_MODIFY_SHIPPING_ADDRESS, params, null);
    }

    public void getShippingAddress() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("memberid", App.getInstance().getUser().memberid);
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_SHIPPING_ADDRESS, params, AddressListResponse.class);
    }
    public void getDefaultAddress() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("memberid", App.getInstance().getUser().memberid);
            jsonObject.put("isdefault","1");
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_SHIPPING_ADDRESS, params, AddressListResponse.class);
    }

    public void deleteShippingAddress(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("addressid", id);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_DELETE_SHIPPING_ADDRESS, params,null);
    }

    public void getServicePack() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_SERVICE_PACK, params, ServicePackResponse.class);
    }

    public void getMyServicePack() {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUser().personid);
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_GET_MY_SERVICE_PACK, params, ServicePackResponse.class);
    }

    public void getServiceDetail(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("pkid",id);
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_SERVICE_PACK_DETAIL, params, null);
    }

    public void isServicePackOrder(String id){
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("pkid",id);
            jsonObject.put("personid", App.getInstance().getUser().personid);
            jsonObject.put("orderstatus", "1");
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_MY_SERVICE_PACK_DETAIL, params, null);
    }

    public void getMyServiceDetail(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("orderid",id);
            PageUtil.addPageJson(jsonObject, 1, 9999);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_MY_SERVICE_PACK_DETAIL, params, null);
    }

    public void orderServicePack(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid",App.getInstance().getUser().personid);
            jsonObject.put("pkid",id);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_ORDER_SERVICE_PACK, params, null);
    }

    public void payServicePack(String orderId,String orderType,String addressId,String phone,String code) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ordertype",orderType);
            jsonObject.put("orderid",orderId);
            jsonObject.put("phone",phone);
            jsonObject.put("addressid",addressId);
            jsonObject.put("code",code);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_PAY_SERVICE_PACK, params, PayInfo.class);
    }

    public void finishServicePack(String id) {
        HttpParams params = new HttpParams();
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("detailid",id);
            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        doPostJson(HttpConstants.API_FINISH_SERVICE_PACK, params, null);
    }

    public void getServiceCode(String phone) {
        HttpParams params = new HttpParams();
            params.addFormParam("mobile", phone);
        doPostJson(HttpConstants.API_SERVICE_ORDER_CODE, params, null);
    }
}
